package com.d4a5.mapping.google2
{
	import com.google.maps.LatLng;
	import com.google.maps.MapMouseEvent;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.Timer;

	public class wmgOverlayMobileLayer extends wmgOverlayLayer
	{
		
		protected var _mouseDownTime:Date;
		protected var _mouseDownLocation:LatLng;
		protected var _timer:Timer;
		
		public function wmgOverlayMobileLayer()
		{
			super();
		}
		
		override protected function onEnterFrame( event:Event ) : void {
			if( this.pane != null && this.pane.map != null ){
				this.removeEventListener( Event.ENTER_FRAME , onEnterFrame );
				
				this.pane.map.addEventListener(MapMouseEvent.MOUSE_DOWN,onMouseDown);
				this.pane.map.addEventListener(MapMouseEvent.MOUSE_UP,onMouseUp);
			}
		}
		
		
		override protected function onMouseClick( event:MapMouseEvent ) : void {
			//this.defaultMouseClickSelection( event.latLng );
		}
		
		override protected function onMouseMove( event:MapMouseEvent ) : void {
			//this.defaultMouseClickSelection( event.latLng );
		}
		
		
		protected function onMouseDown( event:MapMouseEvent ) : void {
			if( this._selectable ){
				this._mouseDownTime = new Date();
				this._mouseDownLocation = event.latLng;
			}
			//this.addEventListener(Event.ENTER_FRAME,onEnterFrameForHoover);
		}
		
		protected function onEnterFrameForHoover( event:Event ) : void {
			if( this._mouseDownTime ) {
				
				var timeSinceMouseDown:Number = ((new Date()).time - this._mouseDownTime.time);
				if( timeSinceMouseDown > 400 ){
					this.defaultMouseMoveHighlighter( this._mouseDownLocation );
					this.removeEventListener(Event.ENTER_FRAME,onEnterFrameForHoover);
					this._mouseDownLocation = null;
					this._mouseDownTime = null;
				}
				
			}
		}
		
		protected function onMouseUp( event:MapMouseEvent ) : void {
			//this.highlighted.removeAll();
			
			if( this._mouseDownTime ){
				var timeSinceMouseDown:Number = ((new Date()).time - this._mouseDownTime.time);
				if( timeSinceMouseDown < 500 ){
					this.defaultMouseClickSelection( this._mouseDownLocation );
				}
				this._mouseDownLocation = null;
				this._mouseDownTime = null;
				this.removeEventListener(Event.ENTER_FRAME,onEnterFrameForHoover);
				trace( timeSinceMouseDown );
			}
		}
		
		
	}
}